#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int main(int argc, char *argv[])       //argv是指针数组表
{
//    printf("stdin:%d\n",stdin->_fileno);
//    printf("stdout:%d\n",stdout->_fileno);
//    printf("stderror:%d\n",stderr->_fileno);

    //设置权限掩码
    umask(0);
    //覆盖写
    //int fd = open("log.txt", O_CREAT | O_WRONLY);
    //清空写
    //int fd = open("log.txt", O_CREAT | O_WRONLY | O_TRUNC, 0666);
    //追加方式写入
    //int fd = open("log.txt", O_CREAT | O_APPEND | O_WRONLY | O_TRUNC, 0666);
    //如果是要使用read函数就需要用只读的方式打开
    int fd = open("log.txt", O_RDONLY);
    if(fd < 0) 
        exit(1);     //open failed

    //int arr[10] = {0,1,2,3,4,5,6,7,8,9};
    //char* arr = (char*)"write noTRUNC";
    //char* arr = (char*)"write append\n";
    //将arr中的数据写入文件描述符fd指向的文件中
    //write(fd,arr,strlen(arr));
    char buffer[20] = {0};
    read(fd,buffer,19);
    printf("buffer: %s\n",buffer);

    return 0;
}









